package org.wddsicmd.app;

import java.lang.String;
import javax.swing.*;
import java.awt.*;

public class HintTextField2 extends JTextField {

    int displayWidth = 0;
	
    public HintTextField2(String hint) {
        _hint = hint;
    }

    public void setDisplayWidth(int width){
	displayWidth = width;
    }
	
    @Override
    public void paint(Graphics g) {
        super.paint(g);
        if (getText().length() == 0) 
	{
            int h = getHeight();
            ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
            Insets ins = getInsets();
            FontMetrics fm = g.getFontMetrics();
            int c0 = getBackground().getRGB();
            int c1 = getForeground().getRGB();
            int m = 0xfefefefe;
            int c2 = ((c0 & m) >>> 1) + ((c1 & m) >>> 1);
            g.setColor(new Color(/*c2*/0xff000000, false));
	    int stringWidth = fm.stringWidth(_hint);
		int startX = ((displayWidth != 0) ? (displayWidth/2) : (getWidth()/2)) - stringWidth/2;
            g.drawString(_hint, /*ins.left*/((startX < 0) ? 0 : startX), fm.getAscent()  + 5/* h / 2 + fm.getAscent() / 2 */ /* - 2*/);
        }
    }
    private final String _hint;
}
